package com.dankegongyu.lib.http.model;

import android.text.TextUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author wupuquan
 * @version 1.0
 * @since 2019/3/22 11:26
 */
public class DKHttpHeaders {

    private Map<String, String> mHeadersMap = new LinkedHashMap<>();

    public DKHttpHeaders() {

    }

    public void addHeader(String key, String value) {
        if (!TextUtils.isEmpty(key) && value != null) {
            this.mHeadersMap.put(key, value);
        }
    }

    public void addHeaders(Map<String, String> map) {
        if (map != null) {
            for (Map.Entry<String, String> item : map.entrySet()) {
                if (!TextUtils.isEmpty(item.getKey()) && item.getValue() != null) {
                    this.mHeadersMap.put(item.getKey(), item.getValue());
                }
            }
        }
    }

    public Map<String, String> getHeaders() {
        return mHeadersMap;
    }

    public void removeHeader(String key) {
        if (!TextUtils.isEmpty(key)) {
            this.mHeadersMap.remove(key);
        }
    }

    public void removeAllHeaders() {
        this.mHeadersMap.clear();
    }

    public boolean isEmpty() {
        return this.mHeadersMap.isEmpty();
    }
}
